####
#
#	Name: Disable UAC Internet Explorer Enhanced Security Script - PowerShell
#	Type: Standard Registry Check, Update Registry
#	Author: Nate Bruneau (nathbr)
#	Date: 8.25.2010
#
####

#REGION Functions 

function Set-RegistryValue($key, $name, $value, $type="String") 
{	    
if ((Test-Path $key) -eq $false) 
{ md $key | Out-Null }    
Set-ItemProperty $key $name $value -type $type
}

function Check-RegistryValue($key, $name, $value){

	if (Test-Path $key){
	$keyobject = Get-Item $key
	$values = Get-ItemProperty $keyobject.PSPath

		if ($values.$name -eq $value){
		return $true
		} else {
		return $false
		}
	} else {
	return $false
	}
}

function Disable-IEESCHelper(){

## Batch Script to Turn off IE Hardening

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" /v "IsInstalled" /t REG_DWORD /d 0 /f | Out-Null
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" /v "IsInstalled" /t REG_DWORD /d 0 /f | Out-Null 




Rundll32 iesetup.dll, IEHardenLMSettings | Out-Null
Rundll32 iesetup.dll, IEHardenUser | Out-Null
Rundll32 iesetup.dll, IEHardenAdmin  | Out-Null

REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}" /f /va | Out-Null
REG DELETE "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components\{A509B1A8-37EF-4b3f-8CFC-4F3A74704073}" /f /va  | Out-Null

}

#ENDREGION Functions

#REGION Parameters
#input parameters
$key = "HKLM:\SOFTWARE\Microsoft\AutoDeploy\"
$name = "DisableIEESC"
$value = 1
$type = "DWord"

#ENDREGION Parameters

#REGION Main

Write-Host -ForegroundColor Yellow "IE ESC: Disabling Internet Explorer Enhanced Security for $env:computername"

if (Check-RegistryValue $key $name $value){
Write-Host -ForegroundColor Gray "IE ESC: Disabling Internet Explorer Enhanced Security for $env:computername already completed. Skipping"
Disable-IEEscHelper # run just in case the setting has been changed since first run.
exit 0
} else {
Set-RegistryValue $key $name $value $type
Disable-IEESCHelper

Write-Host -ForegroundColor Yellow "IE ESC: Disabling Internet Explorer Enhanced Security for $env:computername. COMPLETED"
$global:TrackChangesTotal++
$global:TrackChanges = "Disabled IE ESC for $env:computername"
exit 0
}

#ENDREGION Main
